const multer = require('multer');
const path = require('path');
const fs = require('fs');
// 配置Multer存储选项
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    // 设置上传文件的目录
    const uploadDir = path.join(__dirname, '../','uploads');
    if (!fs.existsSync(uploadDir)) {
      fs.mkdirSync(uploadDir, { recursive: true });
    }
    cb(null, uploadDir);
  },
  filename: function (req, file, cb) {
    // 设置上传文件的名称
    cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
  }
});

// 创建Multer实例
const upload = multer({ storage: storage });
module.exports={
  upload
}